#define _CRT_SECURE_NO_WARNINGS	

#include<stdio.h>
#include<string.h>

int BF_Matching(const char* str, const char* sub)
{
    int i = 0;
    int j = 0;
    int len_str = strlen(str);
    int len_sub = strlen(sub);

    while (i < len_str && j < len_sub)
    {
        if (str[i] == sub[j])
            i++, j++;
        else
            i = i - j + 1, j = 0;
    }

    if (j != len_sub)
        return -1;
    return i - j;
}

int main()
{
    printf("%d\n", BF_Matching("aaaaaaab", "aaab"));
    return 0;
}